package com.videostreaming.controller;

import com.videostreaming.controller.base.BaseDbController;
import com.gooddies.wiring.annotations.WiringComponent;
import com.videostreaming.data.Video;
import com.videostreaming.utils.Utils;
import com.wiringweb.annotations.Controller;
import com.wiringweb.annotations.UrlBinding;
import com.wiringweb.resolution.Resolution;
import com.wiringweb.resolution.VelocityResolution;
import java.util.List;

@Controller
@WiringComponent(singleton = true)
public class MainController extends BaseDbController {

    @UrlBinding("/main\\.html")
    public Resolution main() {
        List<Video> playVideos = getDb().getActiveVideos();
        List<List<Video>> videos;
        if (playVideos != null && !playVideos.isEmpty()) {
            videos = Utils.makeTableFromList(playVideos, 2);
            addRequestParameter("videos", videos);
        }

        return new VelocityResolution("mainPage.vm");
    }
}
